package com.hl.web.fore;


import com.hl.pojo.UserReview;
import com.hl.service.UserReviewService;
import com.hl.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/userReview")
public class UserReviewController {
    @Autowired
    private UserReviewService userReviewService;

    @PostMapping("/add")
    public ResultEntity add(@RequestBody UserReview userReview) {
        userReview.setReviewTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return ResultEntity.ok(userReviewService.add(userReview));
    }
    @GetMapping("/findAll")
    public ResultEntity findAll() {
        return ResultEntity.ok(userReviewService.findAll());
    }
    @PostMapping("/update")
    public ResultEntity update(@RequestBody UserReview userReview) {
        return ResultEntity.ok(userReviewService.update(userReview));
    }

    @GetMapping("/delete")
    public ResultEntity delete(Integer id) {
        return ResultEntity.ok(userReviewService.delete(id));
    }
    @GetMapping("/findById")
    public ResultEntity findById(Integer id) {
        return ResultEntity.ok(userReviewService.findById(id));
    }
    @GetMapping("/findByUserId")
    public ResultEntity findByUserId(Integer userId) {
        return ResultEntity.ok(userReviewService.findByUserId(userId));
    }
    @GetMapping("/findByConsultantId")
    public ResultEntity findByConsultantId(Integer consultantId) {
        return ResultEntity.ok(userReviewService.findByConsultantId(consultantId));
    }
}
